$(function(){
    async function a(){
      const response = await fetch('http://chst.vip:1234/api/getbaicaijiatitle?pageid=1')
      return response  
    } 
    a().then(body=>body.json())
    .then(res=>{
        let txt = ''
        res.result.forEach(item => {
            txt += `<li titleId='${item.titleId}'>${item.title}</li>`
        });
        $('.nav_click ul').html(txt)
        $('.nav_click li').click(function(){
            let titleid = $(this).attr('titleid')
            async function b(){
                const response = await fetch(`http://chst.vip:1234/api/getbaicaijiaproduct?titleid=${titleid}`)
                return response  
                } 
                b().then(body=>body.json())
                .then(res=>{
                let txt = ''
                res.result.forEach(item => {
                    txt += `<li titleId='${item.titleId}'>
                                ${item.productImg}
                                <div>
                                    ${item.productName}
                                    ${item.productPrice}
                                    ${item.productCouponRemain}
                                    ${item.productCoupon}
                                    ${item.productHref}
                                </div>
                            </li>`
                });
                $('.list').html(txt)
            })
        })
    })
    fetch('http://chst.vip:1234/api/getbaicaijiaproduct?titleid=0')
    .then(body=>body.json())
    .then(res=>{
        let txt = ''
        res.result.forEach(item => {
            txt += `<li titleId='${item.titleId}'>
                        ${item.productImg}
                        <div>
                            ${item.productName}
                            ${item.productPrice}
                            ${item.productCouponRemain}
                            ${item.productCoupon}
                            ${item.productHref}
                        </div>
                    </li>`
            
        });
        $('.list').html(txt)
    })
    $('.header_logo').click(function(){
        location.href = '../index.html'
    })
})